package co.yixiang.modules.shop.mapper;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import co.yixiang.modules.shop.entity.YxInvestOrder;
import co.yixiang.modules.shop.web.param.YxInvestOrderQueryParam;
import co.yixiang.modules.shop.web.vo.YxInvestOrderQueryVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.io.Serializable;

/**
 * <p>
 * 认购订单表 Mapper 接口
 * </p>
 *
 * @author hisen
 * @since 2020-06-10
 */
@Repository
public interface YxInvestOrderMapper extends BaseMapper<YxInvestOrder> {

    /**
     * 根据ID获取查询对象
     * @param id
     * @return
     */
    YxInvestOrderQueryVo getYxInvestOrderById(Serializable id);

    /**
     * 获取分页对象
     * @param page
     * @param yxInvestOrderQueryParam
     * @return
     */
    IPage<YxInvestOrderQueryVo> getYxInvestOrderPageList(@Param("page") Page page, @Param("param") YxInvestOrderQueryParam yxInvestOrderQueryParam);


    @Select("select IFNULL(sum(price),0) from yx_invest_order " +
            "where invest_status = 3 and sales_man_id= #{uid} and  DATE_FORMAT(add_time,'%Y%m')=DATE_FORMAT(CURDATE(),'%Y%m')")
    double sumPrice(@Param("uid") int uid);
}
